using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.PharmacyDomain;
using ShivamEMR.Model.DataInterfaces.PharmacyDataInterf;
using ShivamEMR.Model;
//using ShivamEMR.Web.Areas.Pharmacy.Models;

namespace ShivamEMR.Web.Areas.Pharmacy.Controllers
{   
    public class DrugPictureController : Controller
    {
		private readonly IDrugBrandRepository drugbrandRepository;
		private readonly IDrugPictureRepository drugpictureRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public DrugPictureController()
        {
            drugbrandRepository = Registry.RepositoryFactory.GetDrugBrandRepository();
            drugpictureRepository = Registry.RepositoryFactory.GetDrugPictureRepository();
        }

        public DrugPictureController(IDrugBrandRepository drugbrandRepository, IDrugPictureRepository drugpictureRepository)
        {
			this.drugbrandRepository = drugbrandRepository;
			this.drugpictureRepository = drugpictureRepository;
        }

        //
        // GET: /DrugPicture/

        public ViewResult Index()
        {
            //return View(drugpictureRepository.AllIncluding(drugpicture => drugpicture.DrugBrand));
            return View(drugpictureRepository.All);
        }

        //
        // GET: /DrugPicture/Details/5

        public ViewResult Details(System.Guid id)
        {
            return View(drugpictureRepository.Find(id));
        }

        //
        // GET: /DrugPicture/Create

        public ActionResult Create()
        {
			ViewBag.PossibleDrugBrands = drugbrandRepository.All;
            return View();
        } 

        //
        // POST: /DrugPicture/Create

        [HttpPost]
        public ActionResult Create(DrugPicture drugpicture)
        {
            if (ModelState.IsValid) {
                drugpictureRepository.InsertOrUpdate(drugpicture);
                drugpictureRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleDrugBrands = drugbrandRepository.All;
				return View();
			}
        }
        
        //
        // GET: /DrugPicture/Edit/5
 
        public ActionResult Edit(System.Guid id)
        {
			ViewBag.PossibleDrugBrands = drugbrandRepository.All;
             return View(drugpictureRepository.Find(id));
        }

        //
        // POST: /DrugPicture/Edit/5

        [HttpPost]
        public ActionResult Edit(DrugPicture drugpicture)
        {
            if (ModelState.IsValid) {
                drugpictureRepository.InsertOrUpdate(drugpicture);
                drugpictureRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleDrugBrands = drugbrandRepository.All;
				return View();
			}
        }

        //
        // GET: /DrugPicture/Delete/5
 
        public ActionResult Delete(System.Guid id)
        {
            return View(drugpictureRepository.Find(id));
        }

        //
        // POST: /DrugPicture/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(System.Guid id)
        {
            var drugpic = drugpictureRepository.Find(id);
            drugpictureRepository.Delete(drugpic);
            drugpictureRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

